<template>
	<view class="pages">
		<view class="pages-details">
			<view class="pages-details-cotent">
				<!-- <view class="pages-list-item" v-if="loading">
					<up-skeleton
						loading
						rows="5"
						title
						animate
					></up-skeleton>
				</view> -->
				<view class="pages-list-item" style="background-color: #fff;">
					<view class="pages-item-row">
						<text class="pages-hint-title">提交人</text>
						<text class="pages-hint-content">王爱军</text>
					</view>
				</view>
			</view>
		</view>
		
		
		<view class="pages-statistics">
			<view class="pages-bolck-title">
				<text class="pages-bolck-title-ad"></text>
				巡查情况
			</view>
			
      <!-- <view class="pages-item" v-for="item of 6" :key="item" @click="onSkipRouterToTaskItem"> -->
        <view class="record ">
          <view class="record_lists pages-item" v-for="(item, index) in 6" :key="index">
            <view class="flex justify-between">
              <text>禁止违规住人</text>
              <view class="flex">
                <up-icon class="margin-r-20" size="28" space="30" name="checkmark-circle-fill" color="#00c500"></up-icon>
                <up-icon size="28" name="close-circle-fill" color="#00c500"></up-icon>
              </view>
            </view>
          </view>
        </view>
        <view class="u-demo-block">
          <text class="u-demo-block__title">巡查图片</text>
          <view class="u-demo-block__content">
            <u-upload
              :fileList="fileList1"
              @afterRead="afterRead"
              @delete="deletePic"
              name="1"
              multiple
              :maxCount="5"
            ></u-upload>
          </view>
        </view>

        <view class="u-demo-block">
          <text class="u-demo-block__title">整改时间</text>
          <view class="u-demo-block__content color-bule" @click="showDatetimePicker=true"> 请选择> </view>
        </view>

        <view class="u-demo-block">
          <text class="u-demo-block__title">巡查备注</text>
          <view class="u-demo-block__content">
            <u--textarea v-model="value1" placeholder="请输入巡查备注"></u--textarea>
          </view>
        </view>
      <!-- </view> -->
		</view>
		
		<view class="pages-buttons--fill"></view>
		<view class="pages-button">
			<up-button 
				color="#2E90EC" 
				text="提交"
				@click="onSkipRouterToAllocate"
			></up-button>
		</view>

    <view v-if="showDatetimePicker">
      <up-datetime-picker
        :show="showDatetimePicker"
        v-model="value1"
        mode="date"
        @cancel="cancelPicker"
        @confirm="confirmPicker"
      ></up-datetime-picker>
    </view>

	</view>
</template>

<script setup>
import { onLoad, onReachBottom, onPullDownRefresh } from "@dcloudio/uni-app";
import { reactive, ref } from "vue";
import { onHasUserinfoData, onSetUserinfoData, onGetUserinfoData, onGetRoleIdData,  onSetRoleIdData, onSetRolesData, onGetRolesData } from "/common/userinfo.js"
import { onGetTaskDetails } from "/serves/api.js";

let showDatetimePicker = ref(false)

const confirmPicker  = () => {
	showDatetimePicker.value = false
}

const cancelPicker  = () => {
	showDatetimePicker.value = false
}

const loading = ref(true)
const details = ref({})


const onSkipRouterToAllocate  = () => {
	const url = '/pages/allocate/index'
	uni.navigateTo({ url })
}

const onPageGetTaskDetails = async (options) => {
	const { id } = options
	loading.value = true
	
	try{
		const response = await onGetTaskDetails(id)
		const { data } = response
		const { task } = data
		details.value = task
	} finally {
		loading.value = false
	}
}

const tabs = reactive([
	{ name: '部门任务', value: 'dept' },
	{ name: '个人任务', value: 'user' },
]) 
const types = reactive([
	{ name: '巡查任务', value: 'dept' },
	{ name: '处置任务', value: 'user' },
])

const onCallPerson = function () {
	uni.makePhoneCall({
		phoneNumber: '18664306776',
		success: () => {},
		fail: () => {}
	})
}

const scrolltolower  = function(e) {}

// 切换tabs
const onSkipTabs = function (e) {
	console.log(e)
}

const onSelectOrg = function () {
	selectOrgRef.value.onShowPopup()
}

const onSkipRouterToTaskItem = function () {
	const url = '/pages/task/item'
	uni.navigateTo({ url })
	// uni.navigateBack()
}

const fileList1 = ref([]);
const deletePic = (event) => {
  fileList1.value.splice(event.index, 1);
};
// 新增图片
const afterRead = async (event) => {
  // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
  let lists = [].concat(event.file);
  let fileListLen = fileList1.value.length;
  lists.map((item) => {
    fileList1.value.push({
      ...item,
      status: 'uploading',
      message: '上传中',
    });
  });
  for (let i = 0; i < lists.length; i++) {
    const result = await uploadFilePromise(lists[i].url);
    let item = fileList1.value[fileListLen];
    fileList1.value.splice(fileListLen, 1, {
      ...item,
      status: 'success',
      message: '',
      url: result,
    });
    fileListLen++;
  }
};
const uploadFilePromise = (url) => {
  return new Promise((resolve, reject) => {
    let a = uni.uploadFile({
      url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
      filePath: url,
      name: 'file',
      formData: {
        user: 'test',
      },
      success: (res) => {
        setTimeout(() => {
          resolve(res.data.data);
        }, 1000);
      },
    });
  });
}

// onLoad((options) => onPageGetTaskDetails(options))
</script>

<style scoped lang="scss">
.record {
  .record_lists {
    padding: 20rpx 20rpx;
    margin-bottom: 20rpx;
    background: #fafbfe;
  }
}
.u-demo-block {
  flex: 1;
  margin-bottom: 23px;
  .u-demo-block__title {
    font-size: 14px;
    color: #8f9ca2;
    margin-bottom: 8px;
    display: flex;
    flex-direction: row;
  }
}
.pages-details {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	padding: 30rpx;
	padding-bottom: 0;
	background-image: linear-gradient(180deg, #2E90EC 0%, #F2F2F2 90%);
}

.pages-details-cotent {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: space-between;
	
}

.pages-list-item {
	width: 100%;
	height: auto;
	box-shadow: 8rpx 8rpx 16rpx 0px rgba(0,0,0,0.3);
	border-radius: 4rpx;
	box-sizing: border-box;
	padding: 24rpx 30rpx;
	margin-bottom: 30rpx;
	position: relative;
	overflow: hidden;
	transform: all 0.2s;
}

.pages-item-status {
	width: 150rpx;
	height: 150rpx;
	background-color: #317FFC;
	text-align: center;
	font-size: 24rpx;
	color: #FFFFFF;
	box-sizing: border-box;
	padding-top: 110rpx;
	transform: rotate(45deg);
	position: absolute;
	top: -75rpx;
	right: -75rpx;
	box-shadow: 4rpx 4rpx 4rpx 0px rgba(49, 127, 252, .3);
	
	&--warning {
		background-color: #FF9900;
		box-shadow: 4rpx 4rpx 8rpx 0px rgba(255, 153, 0, .3);
	}
	
	&--success {
		background-color: #00C500;
		box-shadow: 4rpx 4rpx 8rpx 0px rgba(0, 197, 0, .3);
	}
}

.pages-item-title {
	font-family: PingFangSC, PingFang SC;
	font-weight: 500;
	font-size: 36rpx;
	color: #171717;
	line-height: 1.5em;
	font-style: normal;
	width: 100%; 
	
	&--tag {
		padding: 5rpx 10rpx;
		font-size: 28rpx;
		color: #FF0000;
		border: 1px solid #FF0000;
		background-color: rgba(255, 0, 0, .1);
		margin-left: 20rpx;
		border-radius: 4rpx;
	}
	
	
}

.pages-item-row {
	width: 100%;
	min-height: 60rpx;
	height: auto;
	box-sizing: border-box;
	padding-top: 10rpx;
	display: flex;
	align-items: flex-start;
}

.pages-hint-title {
	width: 160rpx;
	font-weight: 400;
	font-size: 28rpx;
	color: #666666;
}

.pages-hint-content {
	display: inline-block;
	width: calc(100% - 160rpx);
	font-weight: 500;
	font-size: 28rpx;
	color: #333333;
	transition: all .3s;
	
	&--active {
		padding-top: 5rpx;
		
		&:active {
			opacity: 0.9;
		}
	}
}

.pages-hint-content--flex {
	display: inline-flex;
	align-items: center;
}

.pages-hint-content--hint {
	margin-left: 10rpx;
	font-weight: 400;
	font-size: 28rpx;
	color: #666666;
}

.pages-item-bolck {
	width: 100%;
	height: auto;
}

.pages-bolck-title {
	height: 70rpx;
	display: flex;
	align-items: center;
	font-weight: 500;
	font-size: 30rpx;
	color: #000000;
	box-sizing: border-box;
}

.pages-bolck-title-ad {
	width: 6rpx;
	height: 32rpx;
	background-color: #317FFC;
	border-radius: 3rpx;
	margin-right: 15rpx;
}

.pages-bolck-content {
	width: 100%;
	font-weight: 500;
	font-size: 28rpx;
	color: #333333;
	text-indent: 2em;
	line-height: 1.5em;
}

.pages-statistics {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	padding: 10rpx 30rpx;
	padding-bottom: env(safe-area-inset-bottom);
  background: #fff;
}

.pages-item  {
	width: 100%;
	height: auto;
	background: linear-gradient(0deg, #FFFFFF 0%, #F6F9FF 100%);
	box-shadow: 8rpx 8rpx 16rpx 0px rgba(0,0,0,0.1);
	border-radius: 4rpx;
	box-sizing: border-box;
	padding: 32rpx;
	margin-bottom: 30rpx;
	transform: all 0.2s;
	
	&:active {
		background: linear-gradient(0deg, #FFFFFF 2%, rgba(126, 187, 255, .2) 100%);
		box-shadow: 8rpx 8rpx 16rpx 0px rgba(0,0,0,0.3);
	}
}

.pages-item-title {
	font-family: PingFangSC, PingFang SC;
	font-weight: 500;
	font-size: 32rpx;
	color: #333333;
	text-shadow: 0px 0px 10rpx rgba(109,114,141,0.17);
	text-align: justify;
	font-style: normal;
}

.pages-item-content {
	width: 100%;
	height: auto;
	box-sizing: border-box;
	padding: 20rpx 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
}


.pages-content-item {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	border-right: 1px solid #F6F6F6;
	
	&:last-child {
		border-right: 0;
	}
}

.pages-content-item-font {
	font-weight: 500;
	font-size: 48rpx;
	color: #317FFC;
	line-height: 1.5em;
	text-shadow: 0px 0px 10rpx rgba(109,114,141,0.17);
	text-align: left;
	font-style: normal;
	
	&--warning {
		color: #FF9900;
	}
	
	&--error {
		color: #FF0000;
	}
	
	&--success {
		color: #00C500;
	}
}

.pages-content-item-text {
	font-family: PingFangSC, PingFang SC;
	font-weight: 400;
	font-size: 28rpx;
	color: #999999;
	line-height: 1.5em;
	text-shadow: 0px 0px 10rpx rgba(109,114,141,0.17);
	text-align: left;
	font-style: normal;
}

.pages-buttons--fill {
	width: 100%;
	height: calc(110rpx + env(safe-area-inset-bottom));
}

.pages-button {
	width: 100%;
	height: calc(110rpx + env(safe-area-inset-bottom));
	box-sizing: border-box;
	padding: 30rpx;
	box-shadow: 0px 2px 8px 0px rgba(0,0,0,0.18);
	position: fixed;
	bottom: 0;
	left: 0;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: space-between;
	background-color: #ffffff;
}

</style>